package com.sc.nft.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.controller.request.*;
import com.sc.nft.controller.vo.SecondConsignVO;
import com.sc.nft.dao.*;
import com.sc.nft.dto.EcologyHatchConfDao;
import com.sc.nft.entity.*;
import com.sc.nft.entity.dto.*;
import com.sc.nft.entity.vo.*;
import com.sc.nft.enums.*;
import com.sc.nft.exception.GlobalRunTimeException;
import com.sc.nft.pool.UserPool;
import com.sc.nft.service.*;
import com.sc.nft.sup.ErrorCode;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.HashedMap;
import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * 藏品寄售模块
 *
 * @author zxy
 * @since 2022-10-05 01:04:36
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/consign")
@Api(tags ="藏品寄售模块")
public class ConsignController {
    private final UserCollectionService userCollectionService;
    private final UserCollectionDao userCollectionDao;
    private final SecondCollectionConfigDao secondCollectionConfigDao;
    private final SecondCollectionDao secondCollectionDao;
    private final SecondCollectionService  secondCollectionService;
    private final StaticDataService staticDataService;
    private final UserConsensusDao userConsensusDao;
    private final UserCollectionConsensusDao userCollectionConsensusDao;
    private final SecondOrderDao secondOrderDao;
    private final DigitalCollectionDao digitalCollectionDao;
    private final Redisson redisson;
    private final ShowLevelService showLevelService;
    private final ExitConsensusUserDao exitConsensusUserDao;


    private final String dateFormat = "yyyy-MM-dd";
    private final String dateTimeFormat = "yyyy-MM-dd HH:mm";

//    @ApiOperation(value = "初始化配置表", notes = "初始化配置表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
//    @PostMapping(value = "/initConfig", produces = MediaType.APPLICATION_JSON_VALUE)
//    @UserLogin
//    public Result initConfig() {
//        List<SecondCollectionConfig> list = secondCollectionConfigDao.list();
//        for (SecondCollectionConfig secondCollectionConfig : list) {
//            BigDecimal maxPrice = secondCollectionConfig.getMaxPrice();
//            BigDecimal startPrice = secondCollectionConfig.getStartPrice();
//
//            BigDecimal subtract = maxPrice.subtract(startPrice);
//            BigDecimal bigDecimal = subtract.divide(startPrice, 4, BigDecimal.ROUND_DOWN).stripTrailingZeros();
//            //累积涨幅
//            secondCollectionConfig.setCumulativeIncrease(bigDecimal);
//
//            //拆配总额 = 起始金额 * 倍数
//            BigDecimal disassemblySum = secondCollectionConfig.getStartPrice().multiply(Convert.toBigDecimal(secondCollectionConfig.getDisassemblyMultiple()));
//
//            //剩余拆配天数
//            double log = BigDecimal.ONE.add(secondCollectionConfig.getUpRatio()).doubleValue();
//            double log2 = disassemblySum.divide(maxPrice, 8, BigDecimal.ROUND_DOWN).stripTrailingZeros().doubleValue();
//            //拆配剩余天数
//            secondCollectionConfig.setLastDisassemblyDay(Convert.toInteger(Convert.toBigDecimal(Math.log(log2)).divide(Convert.toBigDecimal(Math.log(log)), 0, BigDecimal.ROUND_UP).stripTrailingZeros()));
//            secondCollectionConfig.setIsDisassembly(Boolean.TRUE);
//            secondCollectionConfig.setDisassemblyMultiple(3);
//            secondCollectionConfig.setBuyShares(BigDecimal.ONE);
//            secondCollectionConfig.setConsignExplanation(
//                    "该藏品目前处于孵化阶段，遵循联动增长机制、交易防囤机制、定期拆配机制:\n" +
//                    "1、联动增长机制：该藏品每天的挂售价格随然每日涨幅（0-2%之间）变化进行浮动;\n" +
//                    "2、持仓防囤机制：该藏品持仓大于1份时，超出部分触发防囤，防囤价为单份成交最大到账金额；\n" +
//                    "3、定期拆配机制：该藏品历史涨幅超过300%时，触发拆配机制历经4次拆配后将会进入自由市场进行流转，具体拆配规则如下：\n" +
//                    "当藏品防囤价小于300元时，\n" +
//                    "拆配结果：市值100元的藏品+（防囤价-100）元的平台红包\n" +
//                    "当藏品防囤价大于300元时，\n" +
//                    "拆配结果：市值100元的藏品+200元的平台红包\n" +
//                    "当藏品未触发防囤机制时，\n" +
//                    "拆配结果：市值100元的藏品+188元平台红包（扣除孵化交易手续费）\n" +
//                    "4、可挂单时间：0：05—11：30，可购买时间：12：00-18：00");
//            secondCollectionConfig.updateById();
//
//        }
//        return PageResult.success();
//    }

    @ApiOperation(value = "1.获取作者列表和品质列表", notes = "获取作者列表和品质列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getConditionQueryList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<ConditionQueryListVO> conditionQueryList() {
        return PageResult.success(secondCollectionService.conditionQueryList());
    }

    @ApiOperation(value = "获取作者列表,分页", notes = "获取作者列表,分页", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getAuthorList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<UserCreatorVO> getAuthorList(@RequestBody PageRequest request) {
        return PageResult.success(secondCollectionService.getAuthorList(request));
    }

    @ApiOperation(value = "获取品质列表", notes = "获取品质列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getQuality", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<List<ShowLevelVO>> getQuality() {
        return Result.success(showLevelService.getAllShowLevelByApp());
    }

    @PostMapping(value = "/getMarketConfig", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取交易时间", notes = "获取交易时间", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<MarketConfigDTO> getMarketConfig() {
        StaticData staticData = staticDataService.getByType("market_config");
        if (ObjectUtil.isNull(staticData)) {
            return Result.success();
        }
        MarketConfigDTO marketConfigDTO = JSONObject.parseObject(staticData.getValue(), MarketConfigDTO.class);
        DateTime now = DateTime.now();
        String today = now.toString(dateFormat);
        DateTime startOne = DateUtil.parse(today+" "+marketConfigDTO.getBuyStartTimeOne(),dateTimeFormat);
        DateTime endOne = DateUtil.parse(today+" "+marketConfigDTO.getBuyEndTimeOne(),dateTimeFormat);
        DateTime startTwo = DateUtil.parse(today+" "+marketConfigDTO.getBuyStartTimeTwo(),dateTimeFormat);
        DateTime endTwo = DateUtil.parse(today+" "+marketConfigDTO.getBuyEndTimeTwo(),dateTimeFormat);
        if(DateUtil.isIn(now,startOne,endOne)||DateUtil.isIn(now,startTwo,endTwo)){
            marketConfigDTO.setCountDown(0L);
            return Result.success(marketConfigDTO);
        }
        if(now.before(startOne)){
            marketConfigDTO.setCountDown(DateUtil.betweenMs(now,startOne)/1000);
            return Result.success(marketConfigDTO);
        }
        if(now.after(endOne)&&now.before(startTwo)){
            marketConfigDTO.setCountDown(DateUtil.betweenMs(now,startTwo)/1000);
            return Result.success(marketConfigDTO);
        }
        if(now.after(endTwo)){
            startOne.offset(DateField.DAY_OF_MONTH,1);
            marketConfigDTO.setCountDown(DateUtil.betweenMs(now,startOne)/1000);
            return Result.success(marketConfigDTO);
        }
        return Result.success(marketConfigDTO);
    }


    @PostMapping(value = "/getFreeMarketConfig", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取自由市场交易时间", notes = "获取自由市场交易时间", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<MarketConfigDTO> getFreeMarketConfig() {
        StaticData staticData = staticDataService.getByType("free_market_config");
        if (ObjectUtil.isNull(staticData)) {
            return Result.success();
        }
        MarketConfigDTO marketConfigDTO = JSONObject.parseObject(staticData.getValue(), MarketConfigDTO.class);
        DateTime now = DateTime.now();
        String today = now.toString(dateFormat);
        DateTime startOne = DateUtil.parse(today+" "+marketConfigDTO.getBuyStartTimeOne(),dateTimeFormat);
        DateTime endOne = DateUtil.parse(today+" "+marketConfigDTO.getBuyEndTimeOne(),dateTimeFormat);
        DateTime startTwo = DateUtil.parse(today+" "+marketConfigDTO.getBuyStartTimeTwo(),dateTimeFormat);
        DateTime endTwo = DateUtil.parse(today+" "+marketConfigDTO.getBuyEndTimeTwo(),dateTimeFormat);
        if(DateUtil.isIn(now,startOne,endOne)||DateUtil.isIn(now,startTwo,endTwo)){
            marketConfigDTO.setCountDown(0L);
            return Result.success(marketConfigDTO);
        }
        if(now.before(startOne)){
            marketConfigDTO.setCountDown(DateUtil.betweenMs(now,startOne)/1000);
            return Result.success(marketConfigDTO);
        }
        if(now.after(endOne)&&now.before(startTwo)){
            marketConfigDTO.setCountDown(DateUtil.betweenMs(now,startTwo)/1000);
            return Result.success(marketConfigDTO);
        }
        if(now.after(endTwo)){
            startOne.offset(DateField.DAY_OF_MONTH,1);
            marketConfigDTO.setCountDown(DateUtil.betweenMs(now,startOne)/1000);
            return Result.success(marketConfigDTO);
        }
        return Result.success(marketConfigDTO);
    }

//    public static void main(String[] args) {
//        DateTime now = DateTime.now();
//        String today = now.toString("yyyy-MM-dd");
//        DateTime startOne = DateUtil.parse(today+" "+"13:00","yyyy-MM-dd HH:mm");
//        DateTime endOne =  DateUtil.parse(today+" "+"15:00","yyyy-MM-dd HH:mm");
//        long beginOne = DateUtil.between(now, startOne, DateUnit.MS, false);
//        System.out.println(beginOne);
//    }

    @ApiOperation(value = "搜索二级市场", notes = "搜索二级市场", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/searchCollectionPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<SecondCollectionConfigDTO> searchCollectionPage(@Valid @RequestBody SecondCollectionRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//        return PageResult.success(secondCollectionConfigDao.searchCollectionPage(request.getShowLevel(),request.getUserCreatorId(),request.getSortType(),request.getFirstTitle(),request.getPageNo(),request.getPageSize()));

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }

    @ApiOperation(value = "2.藏品列表(市场)", notes = "藏品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/collectionPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<SecondCollectionConfigDTO> collectionPage(@Valid @RequestBody SecondCollectionRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//
//        return PageResult.success(secondCollectionConfigDao.page(request.getShowLevel(),request.getUserCreatorId(),request.getSortType(),request.getPageNo(),request.getPageSize()));

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }

    @ApiOperation(value = "3.寄售列表", notes = "寄售列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/consignPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<ConSignCollectionPageDTO> consignPage(@Valid @RequestBody SecondCollectionPageRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//
//        SecondCollectionConfig secondCollectionConfig = secondCollectionConfigDao.getById(request.getId());
//        if(ObjectUtil.isNull(secondCollectionConfig)||BooleanUtil.isFalse(secondCollectionConfig.getStatus())){
//            return PageResult.fail(ErrorCode.NOT_CON_SIGN);
//        }
//        return PageResult.success(secondCollectionDao.getConsignPage(secondCollectionConfig.getCollectionId(),request.getSortType() ,request.getPageNo(),request.getPageSize()));

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }

    @ApiOperation(value = "可寄售藏品列表", notes = "可寄售藏品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/toConsignCollectionList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<SecondConsignDetailAndListVO>  toConsignCollectionList(@Valid @RequestBody CollectionIdRequest request) {
        SecondCollectionConfig secondCollectionConfig = secondCollectionConfigDao.getByCollectionIdAndStatus(request.getCollectionId());
        if(ObjectUtil.isNull(secondCollectionConfig)){
            return PageResult.fail(ErrorCode.NOT_CON_SIGN);
        }

        SecondConsignDetailAndListVO secondConsignDetailAndListVO = new SecondConsignDetailAndListVO();
        secondConsignDetailAndListVO.setMarketType(BeanUtil.isNotEmpty(secondCollectionConfig)?secondCollectionConfig.getMarketType():null);
        DigitalCollection digitalCollection = digitalCollectionDao.getById(secondCollectionConfig.getCollectionId());
        secondConsignDetailAndListVO.setId(digitalCollection.getId());
        secondConsignDetailAndListVO.setFirstTitle(digitalCollection.getFirstTitle());
        secondConsignDetailAndListVO.setCreationContent(digitalCollection.getCreationContent());
        // 2022年11月7日16:05:51 最新成交价修改
        BigDecimal newDeal = digitalCollection.getNewDeal();
        //藏品发售价
        BigDecimal issuePrice = digitalCollection.getIssuePrice();
        issuePrice = ObjectUtil.isNull(issuePrice) ? BigDecimal.ZERO : issuePrice;

        // 2022年11月7日16:05:51 最新成交价修改
        secondConsignDetailAndListVO.setFinalPrice(digitalCollection.getNewDeal().toPlainString());
        secondConsignDetailAndListVO.setIssuePrice(issuePrice.setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
        DigitalCollection collection = digitalCollectionDao.getEcologyCollectionById(secondCollectionConfig.getCollectionId());
        secondConsignDetailAndListVO.setMinPrice(secondCollectionConfig.getMinPrice().setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
        secondConsignDetailAndListVO.setMaxPrice(secondCollectionConfig.getMaxPrice().setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
        if(ObjectUtil.isNotNull(collection)){
            ExitConsensusUser exitConsensusUser = exitConsensusUserDao.getByUserId(UserPool.getUser().getId());
            if(ObjectUtil.isNotNull(exitConsensusUser)&&exitConsensusUser.getStatus()){

            }else{
                secondConsignDetailAndListVO.setMinPrice(secondCollectionConfig.getConsensusMinPrice().setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
                secondConsignDetailAndListVO.setMaxPrice(secondCollectionConfig.getConsensusMaxPrice().setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
            }
        }

        secondConsignDetailAndListVO.setSumCount(digitalCollection.getSumCount());
        secondConsignDetailAndListVO.setCollectionListVOList(userCollectionDao.getConsignCollectionList(UserPool.getUser().getId(), request.getCollectionId()));
        secondConsignDetailAndListVO.setNewDeal(newDeal.setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
        secondConsignDetailAndListVO.setConsensusNum("0.0");
        secondConsignDetailAndListVO.setIsConsensusCollection(false);
        if(digitalCollection.getCollectionType()== DigitalMarketTypeEnum.ECOLOGY){
            ExitConsensusUser exitConsensusUser = exitConsensusUserDao.getByUserId(UserPool.getUser().getId());
            if(ObjectUtil.isNotNull(exitConsensusUser)&&exitConsensusUser.getStatus()){

            }else{
                UserCollectionConsensus userCollectionConsensus = userCollectionConsensusDao.getBuyUserIdAndCollectionId(UserPool.getUser().getId(), request.getCollectionId());
                secondConsignDetailAndListVO.setConsensusNum(ObjectUtil.isNull(userCollectionConsensus)?"0.0":userCollectionConsensus.getConsensusNum().toPlainString());
                secondConsignDetailAndListVO.setIsConsensusCollection(true);
            }
        }
        return Result.success(secondConsignDetailAndListVO);
    }




    @ApiOperation(value = "可转赠藏品信息", notes = "可转赠藏品信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/toGiveCollectionList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<SecondGiveDetailAndListVO> toGiveCollectionList(@Valid @RequestBody CollectionIdRequest request) {

//        if(secondCollectionConfig.getMarketType() != MarketTypeEnum.BRAND_INCUBATION){
//            throw new GlobalRunTimeException(ErrorCode.PARAM_ERROR);
//        }

        SecondGiveDetailAndListVO giveDetailAndListVO = new SecondGiveDetailAndListVO();
        DigitalCollection digitalCollection = digitalCollectionDao.getById(request.getCollectionId());
        if (!digitalCollection.getIsGive()) {
            return PageResult.fail(ErrorCode.NOT_GIVE);
        }
        giveDetailAndListVO.setId(digitalCollection.getId());
        giveDetailAndListVO.setFirstTitle(digitalCollection.getFirstTitle());
        giveDetailAndListVO.setCreationContent(digitalCollection.getCreationContent());
        // 2022年11月7日16:05:51 最新成交价修改
        BigDecimal newDeal = digitalCollection.getNewDeal();
        //最新成交价
        BigDecimal newPrice = secondOrderDao.getLastPrice(digitalCollection.getId());
        newPrice = ObjectUtil.isNull(newPrice) ? BigDecimal.ZERO : newPrice;
        //藏品发售价
        BigDecimal issuePrice = digitalCollection.getIssuePrice();
        issuePrice = ObjectUtil.isNull(issuePrice) ? BigDecimal.ZERO : issuePrice;

        // 2022年11月7日16:05:51 最新成交价修改
        giveDetailAndListVO.setFinalPrice(digitalCollection.getNewDeal().toPlainString());
        giveDetailAndListVO.setIssuePrice(issuePrice.setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
        giveDetailAndListVO.setSumCount(digitalCollection.getSumCount());
        giveDetailAndListVO.setNewDeal(newDeal.setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
        // 历史最高价.
//        secondConsignDetailAndListVO.setAllTimeHigh();
        return Result.success(giveDetailAndListVO);
    }

    @ApiOperation(value = "条件查询可寄售藏品列表", notes = "可寄售藏品列表v2.6", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/queryToConsignCollectionList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<ConsignCollectionListByNewVO>  queryToConsignCollectionList(@Valid @RequestBody QueryToConsignCollectionListRequest request) {
        SecondCollectionConfig secondCollectionConfig = secondCollectionConfigDao.getByCollectionIdAndStatus(request.getCollectionId());
        if(ObjectUtil.isNull(secondCollectionConfig)){
            throw new GlobalRunTimeException(ErrorCode.NOT_CON_SIGN);
        }
//
//        if(secondCollectionConfig.getMarketType() !=MarketTypeEnum.BRAND_INCUBATION||secondCollectionConfig.getMarketType()!=MarketTypeEnum.COPYRIGHT){
//            throw new GlobalRunTimeException(ErrorCode.PARAM_ERROR);
//        }


        BigDecimal charge = secondCollectionConfig.getCharge();
        charge = ObjectUtil.isNull(charge) ? new BigDecimal("0.06") : charge;
        charge = BigDecimal.ONE.subtract(charge).setScale(2,BigDecimal.ROUND_DOWN);
        return PageResult.success(userCollectionDao.getPageConsignCollectionListByQuery(UserPool.getUser().getId(), request.getCollectionId(), request.getAntiHoardFlag(), request.getAntiHoardPriceSort(),charge,request.getPageNo(),request.getPageSize()));
    }


    @ApiOperation(value = "条件查询可转增藏品列表", notes = "条件查询可转增藏品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/queryToGiveCollectionList", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<GiveCollectionListByNewVO>  queryToGiveCollectionList(@Valid @RequestBody QueryToGiveCollectionListRequest request) {
        return PageResult.success(userCollectionDao.getPageGiveCollectionListByQuery(UserPool.getUser().getId(), request.getCollectionId(), request.getAntiHoardPriceSort(),request.getPageNo(),request.getPageSize()));
    }

    @ApiOperation(value = "计算收入", notes = "计算收入", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/calIncome", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<UserConsignmentCollectionPriceVO>  calIncome(@Valid @RequestBody CalIncomeRequest request) {
        UserConsignmentCollectionPriceVO userConsignmentCollectionPriceVO=new UserConsignmentCollectionPriceVO();
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }

        if(request.getUserCollectionIds().size() == 0){
            return PageResult.fail(ErrorCode.PLEASE_SELECT_AT_LEAST_ONE_ITEM);
        }
        List<UserCollection> userCollections =  userCollectionDao.listByIds(request.getUserCollectionIds());
        for (UserCollection userCollection : userCollections) {
            Assert.isFalse(userCollection.getFreezingStatus() == UserCollectionFreezingStatusEnum.VERY_ACTIVE,()->new GlobalRunTimeException("激活中的藏品不可出售"));
            Assert.isFalse(userCollection.getFreezingStatus() == UserCollectionFreezingStatusEnum.PRESSING,()->new GlobalRunTimeException("挖宝中的藏品不可出售"));
            Assert.isFalse(userCollection.getFreezingStatus() == UserCollectionFreezingStatusEnum.LOCK,()->new GlobalRunTimeException("锁定中的藏品不可出售"));
        }
        SecondCollectionConfig secondCollectionConfig = secondCollectionConfigDao.getByCollectionIdAndStatus(userCollections.get(0).getCollectionId());
        if(ObjectUtil.isNull(secondCollectionConfig)){
            return PageResult.fail(ErrorCode.NOT_CON_SIGN);
        }
        List<UserCollection> hoardList =  userCollections.stream().filter(UserCollection::getAntiHoardFlag).collect(Collectors.toList());
        BigDecimal sumAmount = BigDecimal.ZERO;
        BigDecimal gas = BigDecimal.ZERO;
        int noHoardSize = userCollections.size();
        if(CollUtil.isNotEmpty(hoardList)){
            for (UserCollection userCollection : hoardList) {
                BigDecimal realPrice = request.getOnePrice().multiply(BigDecimal.ONE.subtract(secondCollectionConfig.getCharge()));
                if (secondCollectionConfig.getMarketType()==MarketTypeEnum.BRAND_INCUBATION) {
                    if(userCollection.getAntiHoardPrice().compareTo(realPrice)<0){
                        sumAmount = sumAmount.add(userCollection.getAntiHoardPrice());
                        noHoardSize--  ;
                    }
                }
            }
        }
        gas=gas.add(secondCollectionConfig.getGas()).multiply(Convert.toBigDecimal(userCollections.size()));
        sumAmount = sumAmount.add(request.getOnePrice().multiply(BigDecimal.ONE.subtract(secondCollectionConfig.getCharge())).multiply(BigDecimal.valueOf(noHoardSize)).subtract(gas));
        userConsignmentCollectionPriceVO.setPrice(sumAmount.setScale(2,BigDecimal.ROUND_DOWN));
        userConsignmentCollectionPriceVO.setGas(gas.setScale(2, BigDecimal.ROUND_DOWN));
        userConsignmentCollectionPriceVO.setCharge(request.getOnePrice().multiply(secondCollectionConfig.getCharge()).setScale(2,BigDecimal.ROUND_DOWN).multiply(Convert.toBigDecimal(userCollections.size())));
        return Result.success(userConsignmentCollectionPriceVO);
    }

    @ApiOperation(value = "根据用户藏品Id查询藏品寄售信息", notes = "根据用户藏品Id查询藏品寄售信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getSecondCollectionConfig", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<SecondConsignVO>  getSecondCollectionConfig(@Valid @RequestBody IdRequest request) {
        UserCollection userCollection= userCollectionService.getById(request.getId());
        if(ObjectUtil.isNull(userCollection)||userCollection.getUserId().longValue()!=UserPool.getUser().getId().longValue()){
            return Result.fail(ErrorCode.COLLECTION_NOT_FOUND);
        }


        if(userCollection.getFreezingStatus() == UserCollectionFreezingStatusEnum.VERY_ACTIVE){
            return Result.fail("该藏品正在秘境激活中，暂时无法寄售");
        }

        if(userCollection.getFreezingStatus() == UserCollectionFreezingStatusEnum.PRESSING){
            return Result.fail("该藏品正在秘境质押中，暂时无法寄售");
        }

        if(userCollection.getFreezingStatus() == UserCollectionFreezingStatusEnum.LOCK){
            return Result.fail("该藏品正在拍卖锁定中，暂时无法寄售");
        }

        SecondCollectionConfig secondCollectionConfig = secondCollectionConfigDao.getByCollectionIdAndStatus(userCollection.getCollectionId());
        if(secondCollectionConfig.getMarketType() != MarketTypeEnum.BRAND_INCUBATION){
            return Result.fail(ErrorCode.PARAM_ERROR);
        }

        SecondConsignVO secondConsignVO = new SecondConsignVO();
        if(ObjectUtil.isNotNull(secondCollectionConfig)&&secondCollectionConfig.getStatus()){
            DigitalCollection digitalCollection = digitalCollectionDao.getById(secondCollectionConfig.getCollectionId());
            Assert.notNull(digitalCollection,()->new GlobalRunTimeException(ErrorCode.PRODUCT_NOT_FOUND));
            secondConsignVO.setCreationContent(digitalCollection.getCreationContent());
            secondConsignVO.setFirstTitle(digitalCollection.getFirstTitle());
            // 最新成交价
            BigDecimal newDeal = digitalCollection.getNewDeal();
            secondConsignVO.setNewPrice(digitalCollection.getNewDeal());
            //发行价
            BigDecimal issuePrice = digitalCollection.getIssuePrice();
            issuePrice = ObjectUtil.isNull(issuePrice) ? BigDecimal.ZERO: issuePrice;
            secondConsignVO.setIssuePrice(issuePrice.setScale(2, BigDecimal.ROUND_DOWN));
            secondConsignVO.setAllowConsign(true);
            secondConsignVO.setMinPrice(secondCollectionConfig.getMinPrice().setScale(2,BigDecimal.ROUND_DOWN).toPlainString());
            secondConsignVO.setMaxPrice(secondCollectionConfig.getMaxPrice().setScale(2,BigDecimal.ROUND_DOWN).toPlainString());
            secondConsignVO.setCharge(secondCollectionConfig.getCharge().setScale(2,BigDecimal.ROUND_DOWN).toPlainString());
            secondConsignVO.setNewDeal(newDeal.setScale(2,BigDecimal.ROUND_DOWN).toPlainString());
        }else{
            secondConsignVO.setAllowConsign(false);
        }
        return Result.success(secondConsignVO);
    }


    @ApiOperation(value = "藏品寄售", notes = "藏品寄售", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/consign", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result consign(@Valid @RequestBody CollectionConsignRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//
//        RLock lock = redisson.getLock(RedisKeyEnum.CON_SIGN.getKey()+request.getId());
//        try{
//            boolean res = lock.tryLock(3, 10, TimeUnit.SECONDS);
//            if (res) {
//                //获取寄售时间 并且判断是否是在寄售时间内
//                StaticData staticData = staticDataService.getByType("market_config");
//                if(ObjectUtil.isNull(staticData)|| StrUtil.isBlank(staticData.getValue())){
//                    return Result.fail(ErrorCode.NOT_ALLOW_DEAL_TIME);
//                }
//                DateTime now = DateTime.now();
//                String dateStr= now.toString("yyyy-MM-dd");
//                MarketConfigDTO marketConfigDTO = JSONObject.parseObject(staticData.getValue(), MarketConfigDTO.class);
//                DateTime billingStartDate1 = DateUtil.parse(dateStr+" "+marketConfigDTO.getBillingStartTimeOne(),"yyyy-MM-dd HH:mm");
//                DateTime billingEndDate1 = DateUtil.parse(dateStr+" "+marketConfigDTO.getBillingEndTimeOne(),"yyyy-MM-dd HH:mm");
//                DateTime billingStartDate2 = DateUtil.parse(dateStr+" "+marketConfigDTO.getBillingStartTimeTwo(),"yyyy-MM-dd HH:mm");
//                DateTime billingEndDate2 = DateUtil.parse(dateStr+" "+marketConfigDTO.getBillingEndTimeTwo(),"yyyy-MM-dd HH:mm");
//
//                if(!((now.after(billingStartDate1)&&now.before(billingEndDate1))||(now.after(billingStartDate2)&&now.before(billingEndDate2)))){
//                    return Result.fail(ErrorCode.NOT_ALLOW_DEAL_TIME);
//                }
//                if(!StrUtil.equals(request.getDealPassword(),UserPool.getUser().getTransactionPassword())){
//                    return Result.fail(ErrorCode.PASSWORD_ERROR);
//                }
//
//                secondCollectionService.conSign(request.getId(),request.getSalesPrice(),request.getDealPassword());
//            }else {
//                return Result.fail(ErrorCode.LATER_TRY);
//            }
//        } catch (InterruptedException e) {
//            return Result.fail("当前人数过多，请稍后再试");
//        } finally {
//            lock.unlock();
//        }
//        return Result.success();

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }

    @ApiOperation(value = "批量藏品寄售", notes = "批量藏品寄售", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/batchConsign", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result batchConsign(@Valid @RequestBody BatchCollectionConsignRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
        if (!UserPool.getUser().getIsValid()) {
            throw new GlobalRunTimeException("不满足寄售条件");
        }
        RLock lock = redisson.getLock(RedisKeyEnum.CON_SIGN.getKey()+request.getIds().get(0));
        try{
            boolean res = lock.tryLock(3, 10, TimeUnit.SECONDS);
            if (res) {
                //获取寄售时间 并且判断是否是在寄售时间内
                StaticData staticData = staticDataService.getByType("market_config");
                if(ObjectUtil.isNull(staticData)|| StrUtil.isBlank(staticData.getValue())){
                    return Result.fail(ErrorCode.NOT_ALLOW_DEAL_TIME);
                }
                DateTime now = DateTime.now();
                String dateStr= now.toString("yyyy-MM-dd");
                MarketConfigDTO marketConfigDTO = JSONObject.parseObject(staticData.getValue(), MarketConfigDTO.class);
                DateTime billingStartDate1 = DateUtil.parse(dateStr+" "+marketConfigDTO.getBillingStartTimeOne(),"yyyy-MM-dd HH:mm");
                DateTime billingEndDate1 = DateUtil.parse(dateStr+" "+marketConfigDTO.getBillingEndTimeOne(),"yyyy-MM-dd HH:mm");
                DateTime billingStartDate2 = DateUtil.parse(dateStr+" "+marketConfigDTO.getBillingStartTimeTwo(),"yyyy-MM-dd HH:mm");
                DateTime billingEndDate2 = DateUtil.parse(dateStr+" "+marketConfigDTO.getBillingEndTimeTwo(),"yyyy-MM-dd HH:mm");

                if(!((now.after(billingStartDate1)&&now.before(billingEndDate1))||(now.after(billingStartDate2)&&now.before(billingEndDate2)))){
                    return Result.fail(ErrorCode.NOT_ALLOW_DEAL_TIME);
                }
                if(!StrUtil.equals(request.getDealPassword(),UserPool.getUser().getTransactionPassword())){
                    return Result.fail(ErrorCode.PASSWORD_ERROR);
                }

                secondCollectionService.batchConSign(request.getIds(),request.getSalesPrice(),request.getDealPassword());
            }else {
                return Result.fail(ErrorCode.LATER_TRY);
            }
        } catch (InterruptedException e) {
            return Result.fail("当前人数过多，请稍后再试");
        } finally {
            lock.unlock();
        }
        return Result.success();
    }

    @ApiOperation(value = "寄售的藏品详情", notes = "寄售的藏品详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getCollectionDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<SecondCollectionDetailVO> getCollectionDetail(@Valid @RequestBody IdRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//
//        return Result.success(secondCollectionService.getDetailById(request.getId()));

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }

    @ApiOperation(value = "我的寄售藏品列表", notes = "我的寄售藏品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/myConsign", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<MyConSignCollectionPageDTO> myConsign(@Valid @RequestBody PageConsignRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//
//        return PageResult.success(secondCollectionDao.userConsignPage(request.getStatus(),request.getPageNo(),request.getPageSize(),UserPool.getUser().getId()));

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }

    @ApiOperation(value = "我的购买订单(二级订单)", notes = "寄售订单", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/userSecondOrderPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<SecondOrderPageDTO> userSecondOrderPage(@Valid @RequestBody UserSecondOrderRequest request) {

//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//
//        SecondOrderTypeEnum classification = request.getClassification();
//        Page<SecondOrderPageDTO> secondOrderPageDTOPage ;
//        if(classification == SecondOrderTypeEnum.BUY){//买入的订单
//            secondOrderPageDTOPage = secondOrderDao.orderPage(UserPool.getUser().getId(), request.getPageNo(), request.getPageSize());
//        }else{//卖出的订单
//            secondOrderPageDTOPage = secondOrderDao.orderPageBySalesUser(UserPool.getUser().getId(), request.getPageNo(), request.getPageSize());
//        }
//        return PageResult.success(secondOrderPageDTOPage);

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }

    @ApiOperation(value = "订单详情(买入/卖出)", notes = "订单详情(新版本统一使用)", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/userSecondOrderDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<SecondOrderDetailDTO> userSecondOrderDetail(@Valid @RequestBody UserSecondOrderDetailRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//
//        if(request.getClassification() == SecondOrderTypeEnum.BUY){//买入的订单
//            SecondOrderDetailDTO secondOrderDetailDTO =  secondOrderDao.orderDetail(request.getId(),UserPool.getUser().getId());
//            if(ObjectUtil.isNull(secondOrderDetailDTO)){
//                return Result.success();
//            }
//            secondOrderDetailDTO.setCharge("");
//            secondOrderDetailDTO.setRealAmount("");
//            secondOrderDetailDTO.setPreventHoard("");
//            secondOrderDetailDTO.setBuyUserName(UserPool.getUser().getNickName());
//            return Result.success(secondOrderDetailDTO);
//
//        }else if (request.getClassification() == SecondOrderTypeEnum.SELL){//卖出的订单
//            SecondOrderDetailDTO secondOrderDetailDTO =  secondOrderDao.OrderDetailBySalesUserId(request.getId(),UserPool.getUser().getId());
//            if(ObjectUtil.isNull(secondOrderDetailDTO)){
//                return Result.success();
//            }
//            secondOrderDetailDTO.setSalesUserName(UserPool.getUser().getNickName());
//            return Result.success(secondOrderDetailDTO);
//        }
//
//        return Result.success();

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }


    @ApiOperation(value = "我的购买订单", notes = "寄售订单(苹果老版本使用)", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/secondOrderPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<SecondOrderPageDTO> secondOrderPage(@Valid @RequestBody PageRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//
//        return PageResult.success(secondOrderDao.orderPage(UserPool.getUser().getId(),request.getPageNo(),request.getPageSize()));

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }

    @ApiOperation(value = "订单详情", notes = "订单详情(苹果老版本使用)", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/secondOrderDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<SecondOrderDetailDTO> secondOrderDetail(@Valid @RequestBody IdRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//
//        SecondOrderDetailDTO secondOrderDetailDTO =  secondOrderDao.orderDetail(request.getId(),UserPool.getUser().getId());
//        if(ObjectUtil.isNull(secondOrderDetailDTO)){
//            return Result.success();
//        }
//        secondOrderDetailDTO.setBuyUserName(UserPool.getUser().getNickName());
//        return Result.success(secondOrderDetailDTO);

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }

    @ApiOperation(value = "我的成交详情", notes = "我的成交详情(苹果老版本使用)", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/secondOrderDetailBySalesUser", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<SecondOrderDetailBySalesUserDTO> secondOrderDetailBySalesUser(@Valid @RequestBody IdRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//
//        SecondOrderDetailBySalesUserDTO secondOrderDetailBySalesUserDTO =  secondOrderDao.OrderDetailBySalesUser(request.getId(),UserPool.getUser().getId());
//        if(ObjectUtil.isNull(secondOrderDetailBySalesUserDTO)){
//            return Result.success();
//        }
//        secondOrderDetailBySalesUserDTO.setSalesUserName(UserPool.getUser().getNickName());
//        return Result.success(secondOrderDetailBySalesUserDTO);

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }


    @ApiOperation(value = "取消藏品寄售", notes = "取消藏品寄售", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/cancelConsign", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result cancelConsign(@Valid @RequestBody CancelConsignRequest request) {
//        if(true){
//            throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
//        }
//
//        if(!StrUtil.equals(request.getDealPassword(),UserPool.getUser().getTransactionPassword())){
//            return Result.fail(ErrorCode.PASSWORD_ERROR);
//        }
//        SecondCollection secondCollection = secondCollectionDao.getOnShelfUserCollectionId(request.getId());
//        if(ObjectUtil.isNull(secondCollection)||secondCollection.getUserId().longValue()!=UserPool.getUser().getId().longValue()){
//            throw new GlobalRunTimeException(ErrorCode.NO_PRIVILEGED_COLLECTION.getMessage());
//        }
//        secondCollectionService.offShelf(secondCollection);
//
//        return Result.success();

        throw new GlobalRunTimeException(ErrorCode.THE_SYSTEM_IS_BEING_UPGRADED_PLEASE_UPDATE_TO_THE_LATEST_VERSION_LATER);
    }

    @ApiOperation(value = "批量取消藏品寄售", notes = "批量取消藏品寄售", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/cancelConsignBatch", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result cancelConsignBatch(@Valid @RequestBody CancelConsignBatchRequest request) {
        Boolean existGoods=false;
        if(!StrUtil.equals(request.getDealPassword(),UserPool.getUser().getTransactionPassword())){
            return Result.fail(ErrorCode.PASSWORD_ERROR);
        }

        for (Long aLong : request.getId()) {
            SecondCollection secondCollection = secondCollectionDao.getOnShelfUserCollectionId(aLong);
            if(ObjectUtil.isNull(secondCollection)||secondCollection.getUserId().longValue()!=UserPool.getUser().getId().longValue()){
                existGoods=true;
                continue;
            }
            secondCollectionService.offShelf(secondCollection);
        }

        return Result.success(existGoods?"部分藏品未找到":ErrorCode.SUCCESS.getMessage());
    }

    @ApiOperation(value = "是否开市", notes = "是否开市", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/startTrading", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams(
            @ApiImplicitParam(name = "是否开市", value = "isStart")
    )
    @UserLogin
    public Result startTrading() {
        Map map = new HashedMap();
        StaticData staticData = staticDataService.getByType("market_config");
        MarketConfigDTO marketConfigDTO = JSONObject.parseObject(staticData.getValue(), MarketConfigDTO.class);
        DateTime now = DateTime.now();
        String dateStr = now.toString("yyyy-MM-dd");
        DateTime buyStartDate1 = DateUtil.parse(dateStr + " " + marketConfigDTO.getBuyStartTimeOne(), "yyyy-MM-dd HH:mm");
        DateTime buyEndDate1 = DateUtil.parse(dateStr + " " + marketConfigDTO.getBuyEndTimeOne(), "yyyy-MM-dd HH:mm");
        DateTime buyStartDate2 = DateUtil.parse(dateStr + " " + marketConfigDTO.getBuyStartTimeTwo(), "yyyy-MM-dd HH:mm");
        DateTime buyEndDate2 = DateUtil.parse(dateStr + " " + marketConfigDTO.getBuyEndTimeTwo(), "yyyy-MM-dd HH:mm");
        if (!((now.after(buyStartDate1) && now.before(buyEndDate1)) || (now.after(buyStartDate2) && now.before(buyEndDate2)))) {
            if (now.before(buyStartDate1)) {
                map.put("time", buyStartDate1.getTime() - now.getTime());
            }
            if (now.after(buyStartDate1) && now.before(buyStartDate2)) {
                map.put("time", buyStartDate2.getTime() - now.getTime());
            } else if (now.after(buyEndDate2)){
                DateTime dateTime = DateUtil.offsetDay(buyStartDate1, 1);
                map.put("time", dateTime.getTime()-now.getTime());
            }
            map.put("isStart", Boolean.FALSE);
            return Result.success(map);
        }
        map.put("time", 0L);
        map.put("isStart", Boolean.TRUE);
        return Result.success(map);
    }


}